next up previous contents index
Next: Set constructors Up: Expressions Previous: Expression syntax

Function calls

Function calls are part of expressions (although, using extended syntax, they can be statements too). They are constructed as follows:


Function calls

syntdiag2750

syntdiag2754

syntdiag2758

The variable reference must be a procedural type variable referce. A method designator can only be used in side the method of an object. A qualified method designator can be used outside object methods too.

The function that will get called is the function with a declared parameter list that matches the actual parameter list. This means that

  1. The number of actual parameters must equal the number of declared parameters.
  2. The types of the parameters must be compatible. For varriable reference parameters, the parameter types must be exactly the same.

If no matching function is found, then the compiler will generate an error. Depending on the fact of the function is overloaded (i.e. multiple functions with the same name, but different parameter lists) the error will be different.

There are cases when the compiler will not execute the function call in an expression. This is the case when you are assigning a value to a procedural type variable, as in the following example:
listing2714
In the above listing, the assigment to F will not cause the function AddOne to be called. The assignment to N, however, will call AddOne.

A problem with this syntax is the following construction:
listing2718
Should the compiler compare the addresses of F and AddOne, or should it call both functions, and compare the result ? Free Pascal solves this by deciding that a procedural variable is equivalent to a pointer. Thus the compiler will give a type mismatch error, since AddOne is considered a call to a function with integer result, and F is a pointer, Hence a type mismatch occurs.

How then, should one compare whether F points to the function AddOne ? To do this, one should use the address operator @:
listing2725
The left hand side of the boolean expression is an address. The right hand side also, and so the compiler compares 2 addresses.

How to compare the values that both functions return ? By adding an empty parameter list:
listing2727

Remark that this behaviour is not compatible with Delphi syntax.


next up previous contents index
Next: Set constructors Up: Expressions Previous: Expression syntax

Michael Van Canneyt
Fri Sep 25 09:15:40 MEST 1998